import {
  assetsList,
  assetsRelationship,
  assetsBatchReport,
  assetsBatchMonitor,
  assetsBatchOffline,
  assetsBatchOnline,
  assetsSave,
  assetsDetail,
  assetsDelete,
  urlSensitivelist,
  assetsSaveSubsystem,
  assetsSubsystemBatchReport,
  assetsSubsystemBatchMonitor,
  assetsSubsystemBatchOffline,
  assetsSubsystemBatchOnline,
} from "@/api/propertyManage";
const state = {
  listData: [], //列表数据
  relationship: {}, //部门及负责人
};

const mutations = {
  SET_LISTDATA: (state, data) => {
    state.listData = data;
  },
  SET_RELATION: (state, data) => {
    state.relationship = data;
  },
};

const actions = {
  getAssetsList({ commit }, params) {
    return new Promise((resolve, reject) => {
      assetsList(params)
        .then((res) => {
          commit("SET_LISTDATA", res.data);
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  // 获取部门及负责人
  relationship({ commit }, params) {
    return new Promise((resolve, reject) => {
      assetsRelationship(params)
        .then((res) => {
          commit("SET_RELATION", res.data);
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  // 发起审计 /assets/batchReport
  batchReport({ commit }, params) {
    return new Promise((resolve, reject) => {
      assetsBatchReport(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  // 子系统发起审计 /assets/batchReport
  subsystemBatchReport({ commit }, params) {
    return new Promise((resolve, reject) => {
      assetsSubsystemBatchReport(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  // 发起监控 /assets/batchMonitor
  batchMonitor({ commit }, params) {
    return new Promise((resolve, reject) => {
      assetsBatchMonitor(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  // 子系统发起监控
  subsystemBatchMonitor({ commit }, params) {
    return new Promise((resolve, reject) => {
      assetsSubsystemBatchMonitor(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  // 下线 /assets/batchOffline
  batchOffline({ commit }, params) {
    return new Promise((resolve, reject) => {
      assetsBatchOffline(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  // 下线 /assets/batchOffline
  subsystemBatchOffline({ commit }, params) {
    return new Promise((resolve, reject) => {
      assetsSubsystemBatchOffline(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  // 上线 /assets/batchOnline
  batchOnline({ commit }, params) {
    return new Promise((resolve, reject) => {
      assetsBatchOnline(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  // 上线 /assets/batchOnline
  subsystemBatchOnline({ commit }, params) {
    return new Promise((resolve, reject) => {
      assetsSubsystemBatchOnline(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  // 保存 /assets/save
  save({ commit }, params) {
    return new Promise((resolve, reject) => {
      assetsSave(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  // 查询
  detail({ commit }, params) {
    return new Promise((resolve, reject) => {
      assetsDetail(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  delete({ commit }, params) {
    return new Promise((resolve, reject) => {
      assetsDelete(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  //敏感url table
  urlSensitivelist({ commit }, params) {
    return new Promise((resolve, reject) => {
      urlSensitivelist(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  // 保存子系统
  saveSubsystem({ commit }, params) {
    return new Promise((resolve, reject) => {
      assetsSaveSubsystem(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
